package com.ryan.route.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ryan.route.entity.RouteCollect;
import com.ryan.route.entity.frontvo.RouteCollectVo;
import com.ryan.route.mapper.RouteCollectMapper;
import com.ryan.route.service.RouteCollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 路线收藏 服务实现类
 * </p>
 *
 * @author ryan
 * @since 2020-08-03
 */
@Service
public class RouteCollectServiceImpl extends ServiceImpl<RouteCollectMapper, RouteCollect> implements RouteCollectService {

    /**
     * 判断是否已经收藏
     * @param routeId
     * @param memberId
     * @return
     */
    @Override
    public boolean isCollect(String routeId, String memberId) {
        QueryWrapper<RouteCollect> wrapper = new QueryWrapper<>();
        wrapper.eq("route_id",routeId);
        wrapper.eq("member_id",memberId);
        Integer count = baseMapper.selectCount(wrapper);
        return count>0;
    }

    /**
     * 移除收藏
     * @param routeId
     * @param memberId
     * @return
     */
    @Override
    public int removeCollect(String routeId, String memberId) {
        QueryWrapper<RouteCollect> wrapper = new QueryWrapper<>();
        wrapper.eq("route_id",routeId);
        wrapper.eq("member_id",memberId);
        return baseMapper.delete(wrapper);
    }

    /**
     * 根据会员id获取所有收藏列表
     * @param memberId
     * @return
     */
    @Override
    public List<RouteCollectVo> getCollectList(String memberId) {
        return baseMapper.getCollectList(memberId);
    }
}
